package com.ym.domain.common.base;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
public class Result implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    public static final int CODE_SUCCESS = 200;
    public static final int CODE_FAIL = 500;
    public static final String MSG_SUCCESS = "操作成功";
    public static final String MSG_FAIL = "操作失败";


    private int code;
    private String message;
    private Object data;

    public static Result success() {
        Result result = new Result();
        result.setCode(CODE_SUCCESS);
        result.setMessage(MSG_SUCCESS);
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(CODE_SUCCESS);
        result.setMessage(MSG_SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result success(String message, Object data) {
        Result result = new Result();
        result.setCode(CODE_SUCCESS);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.setCode(CODE_FAIL);
        result.setMessage(MSG_FAIL);
        return result;
    }

    public static Result fail(Object data) {
        Result result = new Result();
        result.setCode(CODE_FAIL);
        result.setMessage(MSG_FAIL);
        result.setData(data);
        return result;
    }

    public static Result fail(String message, Object data) {
        Result result = new Result();
        result.setCode(CODE_FAIL);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

}
